﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
<style type="text/css">

</style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame" style="height:650px;overflow-y:scroll;"  >
<div class="box box-primary" id="more" style="width:110px;height:35px;background-color:#222c32;position:absolute;z-index:9999;left:850px;top:100px;display:none;font-size:12px;border-top-color:#222c32;">
            <div class="box-body home-message" id="moreOp" >
            </div>
</div>
	<section class="content-header">
		<h1>公示详情</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active"><a href="#">分类采购</a></li>
			<li class="active"><a href="#">药品招标管理</a></li>
			<li class="active"><a href="#">资质管理</a></li>
			<li class="active"><a href="#">公示详情</a></li>
		</ol>		
</section>


<section class="content" >
<div>
 <div class="row productall">
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
            	<div class="modal-content">
                	<div class="modal-header bg-primary">
                    	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    	<h5 class="modal-title" id="exampleModalLabel">公示新增</h5>
                    </div>
               <form role="form" class="form-horizontal" id="form" action="/medstgmini/bidPubSettings/addExecScriptFile.html"   method="post">
                 <div class="box-body"> 
                    <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>公示名称：</label>
                        <div class="col-sm-9 text-left">
                            <input class=" form-control" placeholder="公示名称" name="scriptName" id="scriptName" type="text" maxlength="512" />
                        </div>
                    </div>
                    <div class="form-group form-group-xs scriptFileParent">
                        <label class="col-sm-2 text-right"><span class="required">*</span>公示脚本：</label>
                        <div class="col-sm-9 text-left">
                              <textarea class="form-control" rows="10" cols="10" placeholder="公示脚本" id="scriptFile" name="scriptFile" maxlength="4000" ></textarea>
                        </div>
                    </div>
                </div> 
                <input type="hidden" id="bidPubSettingsId" name="bidPubSettingsId" value="" />
                <input type="hidden" id="projId" name = "projId" value="${projId}"/>
            </form>
                    <div class="modal-footer" style="text-align: center;">
                     <input hidden="true" id="spid"/>
           			   <input hidden="true" id="spfatherid"/>
           			    <button type="button" class="btn btn-primary btn-sm" id="preview" onclick="preview();">预&nbsp;览</button>
           			    <label id="submit" class="btn btn-primary btn-sm" >提&nbsp;交</label>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal" id="closeDicCompType">关&nbsp;闭</button>
                    </div>
                </div>
            </div>
        </div>
 </div>
</div>
<table class="jqgrid" id="gridlist"></table>

	<div class="box box-warning bottongroup">
			<label id="addNew" class="btn btn-default btn-sm">新&nbsp;增</label>
			<label id="allOk" class="btn btn-default btn-sm" onclick='javascript:history.go(-1)'>返&nbsp;回</label>
		</div>
</section>
</body>
</html>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">


$(function () {
    $("#gridlist").jqGrid({
        url: "getDetailList.html?projId=${projId}",
        mtype: "POST",
        datatype: "json",
        autowidth: true,
        height: 270,                   	
        colNames: ['操作','公示名称','脚本上传人','脚本上传时间','脚本执行人','公布时间','状态'],
        colModel: [
                { name: 'operate', width: "15%",align: 'center',sortable: false,
	              formatter : function(val, opts, rowdata) {
		          var str = "";                    
		          str += "<a href=\"javascript:edit('"+rowdata.scriptName+"','"+rowdata.bidPubSettingsId+"');\" style=\"display:block;height:24px;width:40px;margin:0 ;padding:0 ;float:left;line-height:24px\">编辑</a>";
                  str +="<div id='"+rowdata.bidPubSettingsId+"d' onmouseover=\"over('"+rowdata.bidPubSettingsId+"');\" style='height:24px;width:40px;margin:0 ;padding:0 ;float:left;line-height:24px'><a>更多...</a></div>";
                  return str;
	                }
                },
				{ name: 'scriptName', width: "10%",align: 'center',sortable: false},		
				{ name: 'scriptSubmitUser', width: "15%",align: 'center' ,sortable: false},
				{ name: 'scriptSubmitDatetime', width: "15%",align: 'center' ,sortable: false,
					formatter : function(val, opts, rowdata) {
						return new Date(val).format("yyyy-MM-dd hh:mm:ss");
					}
				},
				{ name: 'execUser', width: "15%",align: 'center' ,sortable: false},
				{ name: 'execDatetime', width: "15%",align: 'center' ,sortable: false,
					formatter : function(val, opts, rowdata) {
						if(val!=null){
							return new Date(val).format("yyyy-MM-dd hh:mm:ss");
						}else{
							return "";
						}
					}
				},
				{ name: 'status', width: "15%",align: 'center' ,sortable: false,
					formatter : function(val, opts, rowdata) {
						return val == 0?"新建":(val==1?"已执行":"其他");
					}
				}
				
        ],
        rowNum: 20,
        rowList: [10, 20, 50,100],
        rownumbers: true,
        pager: "#gridpage",
        viewrecords: true,
        caption: "公示详情列表",
        jsonReader: {
        	repeatitems: false,
        	id: "compRegId"
        }
    });
    $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
});

	function getList(postData){
			$.post('getComplainResultList.html?projId=${projId}',
					postData, function(result) {
						if (result.success) {
							var html = template('test', result);
							$('#content').append(html);
							records=result.records;  //总条数
						} else {
							$.HN.message.alert("数据获取失败", '信息', 'error');
						}
					}, "json");
		}
	$('#addNew').click(function() {
		$('#preview').show()
		$('#scriptFile').parent().parent('.scriptFileParent').show();
	     $('#scriptName').val("");
         $('#bidPubSettingsId').val("");
		$('#exampleModalLabel').html("公示新增");
		$('#exampleModal').modal({
			keyboard : true
		});
		$("#submit").unbind("click");
		$("#submit").bind("click",function(){
			if (validate()) {
				$.HN.message.confirm('确定要提交吗？', '提示信息', '确定').on(
						function(e) {
							if (e) {
								$("#form").attr("action","/medstgmini/bidPubSettings/addExecScriptFile.html");
								$("#form").ajaxSubmit(
										{
											dataType : "json",
											timeout : 10000,
											success : function(result, statusText) {
												if (result.success) {
													$('#exampleModal').modal('hide');
													$("#gridlist").jqGrid().trigger("reloadGrid");
													$.HN.message.alert("操作成功！", "消息","success");
												} else {
													$.HN.message.alert(result.msg
															|| "提交失败！", "消息", "error");
												}
											}
										});
							}
						});
				}
	    });
	});
	function validate() {
		var scriptName = $.trim($("#scriptName").val());
		if (scriptName == null || scriptName == "") {
			$.HN.message.alert("请输入公示名称！", "消息", "info");
			return false;
		}
		var scriptFile = $.trim($("#scriptFile").val());
		if (scriptFile == null || scriptFile == "") {
			$.HN.message.alert("请输入执行脚本语句！", "消息", "info");
			return false;
		}
		return true;
	}
	function validateEdit() {
		var scriptName = $.trim($("#scriptName").val());
		if (scriptName == null || scriptName == "") {
			$.HN.message.alert("请输入公示名称！", "消息", "info");
			return false;
		}
		return true;
	}
	 function edit(scriptName,bidPubSettingsId){
         $('#scriptName').val(scriptName);
         $('#bidPubSettingsId').val(bidPubSettingsId);
         $('#exampleModalLabel').html("公示编辑");
     	 $('#exampleModal').modal({
             keyboard: true
         });
     	$('#scriptFile').parent().parent('.scriptFileParent').hide();
     	$('#preview').hide();
     	$("#submit").unbind("click");
     	$("#submit").bind("click",function(){
			if (validateEdit()) {
				$.HN.message.confirm('确定要提交吗？', '提示信息', '确定').on(
						function(e) {
							if (e) {
								$("#form").attr("action","/medstgmini/bidPubSettings/editExecScriptFile.html");
								$("#form").ajaxSubmit(
										{
											dataType : "json",
											timeout : 10000,
											success : function(result, statusText) {
												if (result.success) {
													$('#exampleModal').modal('hide');
													$("#gridlist").jqGrid().trigger("reloadGrid");
													$.HN.message.alert("操作成功！", "消息","success");
												} else {
													$.HN.message.alert(result.msg || "提交失败！", "消息", "error");
												}
											}
										});
							}
						});
				}
	    });
     }
	 
	  var flag = false;
      var mouseX=0;
      var mouseY=0;
      $(document).mousemove(function(e){
            mouseX=e.pageX;
            mouseY=e.pageY;
            var coord=$("#more").offset();
            if((mouseX<coord.left||mouseX>(coord.left+$("#more").width())||mouseY<coord.top||
                    mouseY>(coord.top+$("#more").height()))&&(mouseX<(coord.left+$("#more").width())||
                            mouseX>(coord.left+$("#more").width()+50)||mouseY<(coord.top+1)||mouseY>(coord.top+24+1))){
                $("#more").hide();
            } 
      }); 
      function over(id){//鼠标移入
          $("#moreOp").children().remove();
          var coord=$("#"+id+"d").offset();
          $("#more").css("top",coord.top-1);
          $("#more").css("left",coord.left-$("#more").width());
          $("#more").show();
          $("#more").css("height",70);
          $("#more").css("padding-top",6);
          $("#moreOp").append("<a id='"+id+"x'  href=\"javascript:exec('"+id+"');\" style='color:#fff'>执行</a>");
          $("#moreOp").append("<br/>")
          $("#moreOp").append("<a id='"+id+"x' target='_blank' href='/medstgmini/bidPubSettings/toDetailResult.html?bidPubSettingsId="+id+"' style='color:#fff'>执行结果</a>");
      }
      
      function exec(bidPubSettingsId){
    		$.HN.message.confirm('确定要执行吗？', '提示信息', '确定').on(
					function(e) {
						if (e) {
						  	  $.post("/medstgmini/bidPubSettings/execScriptFile.html",{"bidPubSettingsId":bidPubSettingsId},function(result){
					    		  if (result.success) {
										$("#gridlist").jqGrid().trigger("reloadGrid");
										$.HN.message.alert("执行成功！", "消息","success");
									} else {
										$.HN.message.alert(result.msg || "提交失败！", "消息", "error");
									}
					    	  },"json");
						}
					});
      }
      
      function preview(){
    	  var sql =  $("#scriptFile").val();
    	  var scriptName = $("#scriptName").val();
    	  var url = "/medstgmini/bidPubSettings/toExecScriptFile.html";
			$.HN.dialog.open({
				"id" : "scriptFile",
				"title" : "预览效果",
				"url" : url,
				"data" : {
					"sql" : sql,
					"scriptName":scriptName
				},
				"width" : 1000,
				"height" : 400,
				"closefunc" : function(params) {
					if (params) {
					}
				}
			});
    	  
    	  
    	  
      }
</script>